Computer software commonly operates in a multi-tasked environment. A multi-tasked environment is an environment that supports concurrent execution of multiple software processes. For example, a computer can simultaneously execute a user application (e.g., a word processor) and another software application that allows a programmer to debug, profile, or simply monitor performance of the user application. The computer's operating system itself can also execute multiple processes running in a multi-tasked environment.
A number of mechanisms exist for implementing multi-tasking, such as preemptive multi-tasking. In one example of preemptive multi-tasking, a scheduler process organizes the various other software processes into a queue and repeatedly cycles through the queue, allowing each process to execute for a predetermined time before it is interrupted to give the next process a turn. The predetermined time may be some very small fraction of a second so that the scheduler process cycles through the queue many times every second, thereby giving the appearance that all of the processes are all running at the same time.
Preemptive multi-tasking can also be employed in a multi-processor environment where the various software processes are competing for cycles on any one of multiple processors. The existence of multiple processors allows multiple processes to execute simultaneously on different processors, but the number of processes generally exceeds the number of processors. Thus, each processor periodically interrupts a currently running process to allow the next scheduled process to take a turn or to handle I/O interrupts and profiling interrupts. The scheduler process allocates time to each process, giving the illusion that all processes are all running at the same time.
Each time a process is interrupted and control is passed to another process, a context switch occurs. A context switch involves saving the “state” of the computer processor and loading the computer processor with the previously saved state for the next process. Most multi-tasked environments are designed so that none of the processes are internally affected by being constantly interrupted and being forced to take turns.
One consequence of operating in a multi-tasked environment is that process execution is hampered since some processes are dormant while other processes execute. In many situations, it becomes important for a programmer to be able to measure the percentage of cycles that are lost (or, conversely, the percentage of cycles that are available) to a user process. Preferably, the lost-cycle measurement is accurate and includes any cycles unavailable to the user process, such as cycles spent in context switching, interrupt handling, interrupt code set-up and tear-down, and I/O processing. Moreover, the measurement numbers should be made easily available for analysis by the programmer.